package cloud.topdaddy.admin.login.controller;

import cloud.topdaddy.admin.login.entity.SliderCaptcha;
import cloud.topdaddy.admin.login.service.SliderCaptchaService;
import cloud.topdaddy.base.common.resp.R;
import jakarta.servlet.http.HttpSession;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 滑块验证控制器
 */
@RestController
@RequestMapping("/sliderCaptcha")
@AllArgsConstructor
public class SliderCaptchaController {

    private final SliderCaptchaService sliderCaptchaService;

    /**
     * 获取滑块验证码
     */
    @GetMapping("/getCaptcha")
    public R<SliderCaptcha> getSliderCaptcha(HttpSession session) {
        SliderCaptcha captcha = sliderCaptchaService.generateSliderCaptcha(session);
        return R.ok(captcha);
    }

    /**
     * 验证滑块位置
     * @param session HTTP会话
     * @param token 验证码唯一标识
     * @param userX 用户滑动后的X坐标
     * @param userY 用户滑动后的Y坐标
     * @return 验证结果
     */
    @PostMapping("/verify")
    public R<Boolean> verifySliderCaptcha(
            HttpSession session,
            @RequestParam String token,
            @RequestParam int userX,
            @RequestParam int userY) {

        boolean result = sliderCaptchaService.verifySliderCaptcha(session, token, userX, userY);
        return R.ok(result);
    }
}

